package com.yida.gwj.config.controller;

import com.yida.common.core.utils.poi.ExcelUtil;
import com.yida.common.core.web.controller.BaseController;
import com.yida.common.core.web.domain.AjaxResult;
import com.yida.common.core.web.page.TableDataInfo;
import com.yida.common.log.annotation.Log;
import com.yida.common.log.enums.BusinessType;
import com.yida.common.security.annotation.RequiresPermissions;
import com.yida.gwj.config.domain.GwjConfBankRate;
import com.yida.gwj.config.domain.request.GwjConfBankRateRequest;
import com.yida.gwj.config.domain.request.GwjConfigBankRateRequest;
import com.yida.gwj.config.service.IGwjConfBankRateService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.util.List;

/**
 * 银行利率配置Controller
 *
 * @author ruoyi
 * @date 2023-03-01
 */
@RestController
@RequestMapping("/rate")
@Api(tags = "银行利率配置")
public class GwjConfBankRateController extends BaseController {
    @Autowired
    private IGwjConfBankRateService gwjConfBankRateService;

    /**
     * 查询银行利率配置列表
     */
    @RequiresPermissions("system:rate:list")
    @GetMapping("/list")
    @ApiOperation("查询银行利率配置列表")
    public TableDataInfo list(GwjConfBankRate gwjConfBankRate) {
        startPage();
        List<GwjConfBankRate> list = gwjConfBankRateService.selectGwjConfBankRateList(gwjConfBankRate);
        return getDataTable(list);
    }

    /**
     * 导出银行利率配置列表
     */
    @RequiresPermissions("system:rate:export")
    @Log(title = "银行利率配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ApiOperation("导出银行利率配置列表")
    public void export(HttpServletResponse response, GwjConfBankRate gwjConfBankRate) {
        List<GwjConfBankRate> list = gwjConfBankRateService.selectGwjConfBankRateList(gwjConfBankRate);
        ExcelUtil<GwjConfBankRate> util = new ExcelUtil<GwjConfBankRate>(GwjConfBankRate.class);
        util.exportExcel(response, list, "银行利率配置数据");
    }

    /**
     * 获取银行利率配置详细信息
     */
    @RequiresPermissions("system:rate:query")
    @GetMapping(value = "/{id}")
    @ApiOperation("获取银行利率配置详细信息")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(gwjConfBankRateService.selectGwjConfBankRateById(id));
    }

    /**
     * 新增银行利率配置
     */
    @RequiresPermissions("system:rate:add")
    @Log(title = "银行利率配置", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation("新增银行利率配置")
    public AjaxResult add(@Validated @RequestBody GwjConfigBankRateRequest request) {
        return toAjax(gwjConfBankRateService.insertGwjConfBankRate(request));
    }

    /**
     * 修改银行利率配置
     */
    @RequiresPermissions("system:rate:edit")
    @Log(title = "银行利率配置", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation("修改银行利率配置")
    public AjaxResult edit(@Validated @RequestBody GwjConfigBankRateRequest request) {
        return toAjax(gwjConfBankRateService.updateGwjConfBankRate(request));
    }

    /**
     * 删除银行利率配置
     */
    @RequiresPermissions("system:rate:remove")
    @Log(title = "银行利率配置", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    @ApiOperation("删除银行利率配置")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(gwjConfBankRateService.deleteGwjConfBankRateByIds(ids));
    }

    @ApiOperation("简单利率计算器")
    @PostMapping("/calculate")
    public AjaxResult calculateSimpleRate(@Valid @RequestBody GwjConfBankRateRequest request) {
        return AjaxResult.success(gwjConfBankRateService.calculateSimpleRate(request));
    }

}
